/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EVENTSERVER_H
#define EVENTSERVER_H

#include <map>
#include <deque>

namespace Chronos {

class Session;

struct Event {
    enum EventType {PLAYER_LOGIN=0, PLAYER_LOGOUT=1};
};


class EventListener {
public:
    virtual ~EventListener() {}
    virtual void notify(Event::EventType event, Session& session) = 0;
};


class EventServer {
public:
	virtual ~EventServer() {}
    virtual void generateEvent(Event::EventType event, Session& session);
    virtual void registerListener(Event::EventType event, EventListener* listener);
    virtual void unregisterListener(const EventListener* listener);
private:
    typedef std::deque<EventListener*> Listeners;
    typedef Listeners::iterator ListenersIter;
    typedef Listeners::const_iterator ListenersConstIter;

    typedef std::map<Event::EventType, Listeners> EventListeners;
    typedef EventListeners::iterator EventListenersIter;
    typedef EventListeners::const_iterator EventListenersConstIter;
    EventListeners eventListeners;
};

}

#endif

